home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 729 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. From: sdouglas@armltd.co.uk (scott douglass)
  2. Message-ID: <sdouglas-1503960936190001@193.131.176.202>
  3. X-Original-Date: Fri, 15 Mar 1996 09:36:19 +0000
  4. Path: in1.uu.net!bounce-back
  5. Date: 15 Mar 96 13:16:10 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: No way to define some extern consts?
  9. Organization: Apple Computer, Inc.
  10. References: <sdouglas-1403961511440001@193.131.176.202> <4iat2h$pk5@clarknet.clark.net>
  11. X-Newsreader: Yet Another NewsWatcher 2.0.2
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMUltqOEDnX0m9pzZAQFtiwF+PE4cum8+fec3eIU8/df0k9Yu83zPbEVl
  14.     jawL/VNZ89/40G9MCRPu/Y6ImWR0dY7i
  15.     =DS/a
  16.  
  17. In article <4iat2h$pk5@clarknet.clark.net>, gusty@clark.net (Harlan
  18. Messinger) wrote:
  19.  
  20. : scott douglass (sdouglas@armltd.co.uk) wrote:
  21. : : Hello all,
  22. : : 
  23. : : Given a class type with only a no-argument contstrutor:
  24. : : 
  25. : : struct T { T(); /* ... */ };  // assume no other ctors
  26. : : 
  27. : : Is there any way to define an extern const object of class T?
  28. :[...]
  29. : You'll declare
  30. :         extern const T t2;
  31. : in the header file, but define
  32. :         const T t2;
  33. : as a global non-static object in the one source file in which you want it
  34. : to reside. 
  35.  
  36. Thanks.  As you mention and Geert-Jan Giezeman pointed out in private
  37. e-mail, the key here is that the definition can be accomplished by having
  38. both and extern declaration and a definition the same translation unit:
  39.  
  40. extern const T t;  // declaration
  41. const T t;  // definition, still extern
  42.  
  43. You can't do it in one declaration but it's not hard after all.
  44.     --scott
  45. ---
  46. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  47. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  48. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  49. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  50. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  51.